<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUserDrawsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_draws', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('user_id')->unsigned()->comment('用户ID');
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->bigInteger('activity_id')->unsigned()->comment('抽奖活动ID');
            $table->foreign('activity_id')->references('id')->on('activities')->onDelete('restrict');
            $table->bigInteger('customer_info_id')->unsigned()->comment('留资ID');
            $table->foreign('customer_info_id')->references('id')->on('customer_infos')->onDelete('restrict');
            $table->datetime('draw_at')->nullable()->comment('抽奖时间');
            $table->text('prize')->nullable()->comment('JSON 格式的奖品信息');
            $table->text('address')->nullable()->comment('JSON 格式的收货地址');
            $table->datetime('address_at')->nullable()->comment('填写收货地址时间');
            $table->string('reason')->nullable()->comment('未中奖备注');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_draws');
    }
}
